#ifndef __GAF_TYPE_H__
#define __GAF_TYPE_H__

#include "GAF_SysIncDef.h"
#include "GAF_Setting.h"

// ****** 系统基础类型定义 ******
#ifndef NUM8		// 1 	%d
/// 8位有符号数值类型
typedef char			NUM8;
#endif

#ifndef UNUM8		// 1	%u
/// 8位无符号数值类型
typedef unsigned char		UNUM8;
#endif

#ifndef UNM16		// 2	%d
/// 16位有符号数值类型
typedef short			UNM16;
#endif

#ifndef UNUM16		// 2	%u
/// 16位无符号数值类型
typedef unsigned short		UNUM16;
#endif

#ifndef NUM32		// 4	%d
/// 32位有符号数值类型
typedef long			NUM32;
#endif

#ifndef UNUM32		// 4	%u
/// 32位无符号数值类型
typedef unsigned long		UNUM32;
#endif

#ifndef NUM64		// 8	%lld
/// 64位有符号数值类型
typedef long long		NUM64;
#endif

#ifndef UNUM64		// 8	%llu
/// 64位无符号数值类型
typedef unsigned long long	UNUM64;
#endif

#ifdef GAF_NUM_64
typedef NUM64			NUM;
typedef UNUM64			UNUM;
#else
typedef NUM32			NUM;
typedef UNUM32			UNUM;
#endif

#ifndef BYTE
/// 字节类型
typedef unsigned char		BYTE;
#endif

#ifndef UINT
/// 无符号整型
typedef unsigned int		UINT;
#endif

#ifndef ULONG
/// 无符号长整型
typedef unsigned long		ULONG;
#endif

/// 内存大小类型
typedef UINT			SIZET;

/// 数组大小类型
typedef UINT			COUNT;


// ****** 常用类型定义 ******
namespace GAF
{
	/// 指针类型
	typedef void*			Pointer;
	/// 运行次数类型
	typedef	ULONG			RunTimes;
	/// 时间类型
	typedef ULONG			TimeTicks;
	/// 颜色数值类型
	typedef ULONG			ColourCode;
}
typedef GAF::Pointer			GAF_DPointer;
typedef GAF::RunTimes			GAF_DRunTimes;
typedef GAF::TimeTicks			GAF_DTimeTicks;
typedef GAF::ColourCode			GAF_DColourCode;

namespace GAF
{
	/// 句柄类型
	typedef Pointer			Handle;
	/// 对象句柄类型
	typedef Handle			ObjectHandle;
	/// 窗口句柄类型
	typedef ObjectHandle		WindowHandle;
	/// 图像句柄类型
	typedef ObjectHandle		ImageHandle;
	/// 字体句柄类型
	typedef ObjectHandle		FontHandle;

}
typedef GAF::Handle			GAF_DHandle;
typedef GAF::ObjectHandle		GAF_DObjectHandle;
typedef GAF::WindowHandle		GAF_DWindowHandle;
typedef GAF::ImageHandle		GAF_DImageHandle;
typedef GAF::FontHandle			GAF_DFontHandle;

/*
namespace GAF
{
	/// 图像混合类型
	typedef UINT			ImageBlendType;
	/// 图像混合枚举
	enum ImageBlendType
	{
		/// 无混合
		GAF_IBT_NOTHING		= 0,
		/// 饱和度混合
		GAF_IBT_SATURATION	= 1 << 1,
	};

	/// 图像变形枚举
	enum EImageTransformType
	{
		GAF_ITT_REVERT,		// 还原
		GAF_ITT_ZOOM,		// 缩放
		GAF_ITT_ANGLE		// 旋转
	};
}
typedef GAF::CreateWindow		GAF_SCreateWindow;
typedef GAF::ImageInfo			GAF_SImageInfo;
*/

namespace GAF
{
	typedef void			(ReleaseFun)(Pointer pVar);

	void				ReleaseVar(Pointer pVar);
	void				ReleaseAry(Pointer pVars);

	struct Agent
	{
		Pointer			pVar;
		ReleaseFun*		pReleaseFun;

					Agent(ReleaseFun* pR, Pointer pV = NULL);
		Pointer			operator*();
		void			Release();
	};
}
typedef GAF::ReleaseFun			GAF_FReleaseFun;
#define GAF_RELEASE_VAR			GAF::ReleaseVar
#define GAF_RELEASE_ARY			GAF::ReleaseAry
typedef GAF::Agent			GAF_SAgent;


// 整型空值
#define NULL_INT			-999999999

namespace GAF
{
	enum GraphicsTypeEx
	{
		/// 命令界面
		GRAPHICS_COMMANDFACE	= 100,
	};

	/// 点结构
	struct Point
	{
		/// 点X轴坐标
		int			nX;
		/// 点Y轴坐标
		int			nY;

		/// 点设置
		void			Set(int x, int y);
	};

	/// 尺寸结构
	struct Size
	{
		/// 尺寸宽度
		UINT			nWidth;
		/// 尺寸高度
		UINT			nHeight;

		/// 尺寸设置
		void			Set(UINT width, UINT height);
	};

	/// 矩形结构
	struct Rect
	{
		/// 矩形左上角X轴坐标
		int			nX;
		/// 矩形左上角Y轴坐标
		int			nY;
		/// 矩形宽度
		UINT			nWidth;
		/// 矩形高度
		UINT			nHeight;

		/// 矩形设置
		void			Set(int x, int y, UINT width, UINT height);
		/// 设置与获得矩形顶部位置
		int			Top(int top = NULL_INT);
		/// 设置与获得矩形底部位置
		int			Button(int button = NULL_INT);
		/// 设置与获得矩形左部位置
		int			Left(int left = NULL_INT);
		/// 设置与获得矩形右部位置
		int			Right(int right = NULL_INT);

		/// 获得矩形尺寸
		Size&			Dimension();
		/// 获得矩形中心点
		Point&			Center();

		/// 判断是否与另一矩形相交
		bool			Intersect(Rect& other);	// 相交
		/// 判断是否包含另一矩形
		bool			Contains(Rect& other);	// 包含

		/// 获得与另一矩形的相切矩形
		Rect			Cut(Rect& other);	// 相切
		/// 获得与另一矩形的组合矩形
		Rect			Compose(Rect& other);	// 组合

		/// 恒等操作符
		bool			operator==(Rect rOther);
		bool			operator!=(Rect rOther);
	};

	/// 颜色结构
	struct Colour
	{
		/// 红色值
		BYTE			bRed;
		/// 绿色值
		BYTE			bGreen;
		/// 蓝色值
		BYTE			bBlue;
		/// 透明通道值
		BYTE			bAlpha;

		/// 颜色设置
		void			Set(BYTE red, BYTE green, BYTE blue, BYTE alpha = 255);

		bool			operator==(const Colour& cOther);
		bool			operator!=(const Colour& cOther);
	};
}
typedef GAF::Point			GAF_SPoint;
typedef GAF::Size			GAF_SSize;
typedef GAF::Rect			GAF_SRect;
typedef GAF::Colour			GAF_SColour;

namespace GAF
{
	/// 方向类型
	typedef unsigned int		Direction;

	/// 区间
	struct Interval
	{
		double			dFrom;
		double			dTo;

		Interval(double dFromVal = 0, double dToVal = 0) :
			dFrom(dFromVal),
			dTo(dToVal){}

		double			HowMuch()
		{
			return dTo - dFrom;
		}
	};

	/// 力度
	struct Power
	{
		double			dBase;
		Direction		dWay;
		double			dChange;
	};

// 	struct Vector
// 	{
// 		Point			atFrom;
// 		double			dPower;
// 	}
}
typedef GAF::Direction			GAF_DDirection;
typedef GAF::Interval			GAF_SInterval;
typedef GAF::Power			GAF_SPower;

#endif
